package com.chen.script.job;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import com.chen.script.annotation.Job;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * @Author: 陈锦龙
 * @Date: 2025/3/21 16:23
 */
@Data
@Slf4j
@Component
@ConfigurationProperties(prefix = "oracle-dmp")
@ConditionalOnProperty(value = "oracle-dmp.enable", havingValue = "true")
public class OracleDmpJob {

    public String url;
    public String targetPath;

    public OracleDmpJob(){
        log.info("初始化 下载oracle的dmp文件 JOB");
    }

    @Job("oracle-dmp")
    public void run() {
        String zipFile = targetPath + "//" + DateUtil.date().toDateStr() + ".zip";
        File file = new File(zipFile);
        if (file.exists()){
            FileUtil.del(file);
        }
        HttpUtil.downloadFile(url, zipFile);
    }
}
